<template>
  <div class="app-container">
    <el-card class="content-edit">
      <div slot="header">提现规则</div>
      <el-form label-width="140px">
        <el-form-item label="每天提现次数：">
          <el-input v-model="form['withdrawNum']" type="number" style="width:360px;"/>
        </el-form-item>
        <el-form-item label="限额设置：">
          <el-checkbox v-model="form['withdrawMaxStatus']">设置每笔最高限额</el-checkbox>
          <el-checkbox v-model="form['withdrawMinStatus']">设置每笔最低限额</el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-input v-model="form['withdrawMax']" :disabled="!form['withdrawMaxStatus']" type="number" style="width: 140px;">
            <span slot="suffix" style="margin-right: 10px;">元</span>
          </el-input>
          <el-input v-model="form['withdrawMin']" :disabled="!form['withdrawMinStatus']" type="number" style="width: 140px;margin-left: 20px;">
            <span slot="suffix" style="margin-right: 10px;">元</span>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateWithdrawRules">保存</el-button>
          <el-button @click="$router.back()">返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: 'FinancialRule',
    data() {
      return {
        form: {
          // 每天提现次数
          withdrawNum: 0,
          // 设置每笔最高状态
          withdrawMaxStatus: false,
          // 设置每笔最高限额
          withdrawMax: '',
          // 设置每笔最低限额
          withdrawMinStatus: false,
          // 设置每笔最低限额
          withdrawMin: ''
        }
      }
    },
    mounted(){
      this.loadData();
    },
    methods: {
      // 加载用户信息
      loadData(){
        (async () => {
          const result = await this.$service.applicationGetWithdrawRules();
          if (result.code === 0) {
            const temp = result.data;
            temp['withdrawMinStatus'] = !!temp['withdrawMinStatus'];
            temp['withdrawMaxStatus'] = !!temp['withdrawMaxStatus'];
            Object.assign(this.form, result.data || {});
          }
        })();
      },
      updateWithdrawRules(){
        console.log(this.form);
        const params = Object.assign({}, this.form);
        params['withdrawMinStatus'] = params['withdrawMinStatus'] ? 1 : 0;
        params['withdrawMaxStatus'] = params['withdrawMaxStatus'] ? 1 : 0;
        (async () => {
          const result = await this.$service.applicationUpdateWithdrawRules(params);
          if (result.code === 0) {
            this.$message.success('操作成功~');
            this.loadData();
          }
        })();
      }
    }
  }
</script>
